﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MFramework
{
    public class DataTable : IEnumerable<KeyValuePair<int, DataTableRow>>
    {
        private Dictionary<int, DataTableRow> rowDic = new Dictionary<int, DataTableRow>();

        internal DataTable() { }

        public DataTableRow GetRow(int ID)
        {
            if (rowDic.ContainsKey(ID))
            {
                return rowDic[ID];
            }
            return null;
        }

        public DataTableRow this[int ID]
        {
            get
            {
                return GetRow(ID);
            }
        }

        public IEnumerator<KeyValuePair<int, DataTableRow>> GetEnumerator()
        {
            return ((IEnumerable<KeyValuePair<int, DataTableRow>>)rowDic).GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return rowDic.GetEnumerator();
        }

        internal void AddRow(int ID, DataTableRow row)
        {
            rowDic.Add(ID, row);
        }
    }
}
